//
//  HWYaoQingJiluViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/10/12.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWYaoQingJiluViewController.h"
#import "HWIncomeMingXiCell.h"

@interface HWYaoQingJiluViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic)UITableView *mainaTableVie;
@property(strong,nonatomic) NSMutableArray *dataMuArr;

@end

@implementation HWYaoQingJiluViewController

-(UITableView *)mainaTableVie {

    if (_mainaTableVie == nil
        ) {

         _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW,kScreenH-40-CF_NavHeight) style:UITableViewStylePlain];
         _mainaTableVie.delegate = self;
         _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        

    }
    return   _mainaTableVie ;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
    // 发送网络请求
    [self sendNetworkRequest];
}






// 发送网络请求
- (void)sendNetworkRequest {
    
    NSString *userID = [HWLocallyStoredData getLoginUserID];
    int  t =  [WMUtil getRandomNumber:101 to:998];
    NSString *tStr = [NSString stringWithFormat:@"%ld%d",[WMUtil getTimeSp],t];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    NSString *signMD5 = [WMUtil md5HexDigest:sign];
    
    
    
    
    self.dataMuArr = [[NSMutableArray alloc]init];
    
    NSDictionary *parametes = @{
                                @"ct" :  @"app",
                                @"ac" : @"app_friend_list",
                                @"ios" : @"1",
                                @"uid" :userID,
                                @"t" :tStr,
                                @"sign": signMD5
                                };
  
    
    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
        
      
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
     //   [MBProgressHUD hideHUD];
        
        
        if ([codeStr intValue] == 1) {
         
           
            self.dataMuArr = response[@"data"];

        } else {
            
             [MBProgressHUD  showError:response[@"message"]];
            
        }
        
        [self.mainaTableVie reloadData];
        
        
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
      
        [MBProgressHUD  showError:@"加载失败"];
        
    }];
    
    
    
    
}



- (void)setupUI {
    self.view.backgroundColor = [UIColor redColor];
    self.mainaTableVie.backgroundColor = RGB(242, 242, 242);
    [self.view addSubview:self.mainaTableVie];
    
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return self.dataMuArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"cellID";
    
    HWIncomeMingXiCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[HWIncomeMingXiCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
    }
    cell.selectionStyle   =  UITableViewCellSelectionStyleNone;
    NSDictionary *dic = self.dataMuArr[indexPath.row];
    cell.dataDic = dic;
    
    return  cell;
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    return  36;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    
    
    return  36;
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 36)];
    view.backgroundColor = RGB(233, 241, 255);
    NSArray *arr = @[@"注册时间",@"好友账号",@"充值金额"];
    for (int i = 0; i < 3; i++) {
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(kScreenW/3*i, 0, kScreenW/3, 36)];
        label.text = arr[i];
        label.font = [UIFont systemFontOfSize:13];
        label.textColor = RGB(51, 51, 51);
        label.textAlignment = NSTextAlignmentCenter;
        [view addSubview:label];
        
    }
    
    for (int i = 0 ; i < 2 ; i++) {
        UIView *shuxiangView = [[UIView alloc]initWithFrame:CGRectMake(kScreenW/3*(i+1), 0, 1, 36)];
        shuxiangView.backgroundColor = RGB(232, 232, 242);
        [view addSubview:shuxiangView];
    }
    
    return  view;
    
}


@end
